/**
 * Copyright (c) 2020 libinbin000
 * SFrame is licensed under the Mulan PSL v1.
 * You can use this software according to the terms and conditions of the Mulan PSL v1.
 * You may obtain a copy of Mulan PSL v1 at:
 *     http://license.coscl.org.cn/MulanPSL
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
 * PURPOSE.
 * See the Mulan PSL v1 for more details.
 */


 import * as log4js from 'log4js';

 export class Log{
     public static log:log4js.Logger = null;
     public static logd:log4js.Logger = null;
 
     public static init():void{
         log4js.configure({
             appenders: {
                 infoLogs: {
                     type: 'dateFile',
                     filename: 'logs/info/',
                     //backups:5,  // 仅保留最新的五个日志文件
                     pattern: "yyyy-MM-dd.log", // 用于确定何时滚动日志的模式
                     alwaysIncludePattern: true,
                     compress: true
                 },
                 errorLogs: {
                     type: 'dateFile',
                     filename: 'logs/error/',
                     //backups:5,  // 仅保留最新的五个日志文件
                     pattern: "yyyy-MM-dd.log", // 用于确定何时滚动日志的模式
                     alwaysIncludePattern: true,
                     compress: true
                 },
                 justErrors: {
                     type: 'logLevelFilter', // 过滤指定level的文件
                     appender: 'errorLogs',  // appender
                     level: 'error'  // 过滤得到error以上的日志
                 },
                 console: {type: 'console'}
             },
             categories: {
                 default: { appenders: ['justErrors', 'infoLogs'], level: 'info' },
                 err: { appenders: ['errorLogs'], level: 'error' },
                 debug: { appenders: ['console'], level: 'debug' }
             }
           });
         
         Log.log = log4js.getLogger();
         Log.logd = log4js.getLogger("debug");
     }
 
     public static debug(msg:string):void{
         Log.logd.debug(msg);
     }
     
     public static info(msg:string):void{
         Log.log.info(msg);
     }
     
 }